package com.ruoyi.project.syl_LiBiao.service.impl;

import com.ruoyi.project.syl_LiBiao.domain.OutpatientPatient;
import com.ruoyi.project.syl_LiBiao.domain.OutpatientPrescription;
import com.ruoyi.project.syl_LiBiao.domain.PrOrReOrCa;
import com.ruoyi.project.syl_LiBiao.mapper.ChargeManagementMapper;
import com.ruoyi.project.syl_LiBiao.service.ChargeManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ChargeManagementServiceImpl implements ChargeManagementService {
    @Autowired
    private ChargeManagementMapper chargeManagementMapper;

    @Override
    public Map selectRegisterId(String registerId) {
        //根据挂号id查询到了病历表,挂号表,处方表
        PrOrReOrCa prOrReOrCa = chargeManagementMapper.selectRegisterId(registerId);
        //根据挂号表的信息查询到患者表和科室表和医生表

        //患者名字
        String patientName = chargeManagementMapper.selectOneOutpatientPatient(prOrReOrCa.getOutpatientRegister().getPatientId());

        //科室名称
        String deptName = chargeManagementMapper.selectOneDeptName(prOrReOrCa.getOutpatientRegister().getDeptId());
        //医生信息(去用户表中查询医生的名字)
        String docktorName = chargeManagementMapper.selectOneHisUser(prOrReOrCa.getOutpatientRegister().getDoctorId());
        List<OutpatientPrescription> outpatientPrescriptions = selectListPre(registerId);

        Map map=new HashMap<>();
        map.put("prOrReOrCa",prOrReOrCa);
        map.put("patientName",patientName);
        map.put("deptName",deptName);
        map.put("docktorName",docktorName);
        map.put("outpatientPrescriptions",outpatientPrescriptions);
        return map;
    }

    /**
     * 根据挂号id 查询对应处方表的集合
     * @param registerId
     * @return
     */
    @Override
    public List<OutpatientPrescription> selectListPre(String registerId) {
        List<OutpatientPrescription> outpatientPrescriptions = chargeManagementMapper.selectListPre(registerId);

        return outpatientPrescriptions;
    }
}
